package objects

import (
	"fmt"
	"venus/common"
	"venus/service/sv_tcp/znet/ztcp"
	"venus/service/sv_ws"
	"venus/util/zconvert"
	"venus/util/zjson"
)

type Player struct {
	Pid          int64 // 玩家唯一Id
	Uuid         int64 // 账号Id
	TimeRegister int64 // 注册时间(ms)
	TimeLogin    int64 // 上次登录时间(ms)

	Level int32 // 等级
	Exp   int64 // 经验

	Gold int64 // 金币
	Gem  int64 // 宝石

	Stamina int64 // 体力
	Energy  int64 // 精力

	VipLevel int32 // Vip等级

	Name string // 姓名

	Conn     *ztcp.TcpConnection `json:"-"` // 绑定客户端链接
	WsClient *sv_ws.Client       `json:"-"` // 绑定ws客户端链接
}

func NewPlayer(pid int64) *Player {
	return &Player{Pid: pid}
}

func (player *Player) TableName() (text string) {
	return fmt.Sprintf("z%d:players", common.ServerId)
}

func (player *Player) DbKey() (text string) {
	return zconvert.Int64ToStr(player.Pid)
}

func (player *Player) ToString() (text string) {
	text = zjson.Str(player)
	return
}
